package com.qf.service.impl;

import com.qf.dao.OrderDetailDao;
import com.qf.entity.Goods;
import com.qf.entity.OrderDetail;
import com.qf.service.GoodsService;
import com.qf.service.OrderDetailService;
import com.qf.utils.MyBatisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author wgy
 * @version V1.0
 * @project gp12_xiaomi
 * @package com.qf.service.impl
 * @description: ${TODO}
 * @date 2022/6/27 14:29
 */
@Service
@Transactional

public class OrderDetailServiceImpl implements OrderDetailService {

    private OrderDetailDao orderDetailDao;

    private GoodsService goodsService;

    @Autowired
    public void setGoodsService(GoodsService goodsService) {
        this.goodsService = goodsService;
    }

    @Autowired
    public void setOrderDetailDao(OrderDetailDao orderDetailDao) {
        this.orderDetailDao = orderDetailDao;
    }

    @Override
    public List<OrderDetail> findByOid(String oid) {

        List<OrderDetail> orderDetailList = orderDetailDao.selectByOid(oid);
        if (orderDetailList != null) {

            for (OrderDetail orderDetail : orderDetailList) {
                Integer pid = orderDetail.getPid();
                Goods goods = goodsService.findById(pid);
                orderDetail.setGoods(goods);
            }
        }
        return orderDetailList;
    }
}
